package main

import (
	"fmt"
	"github.com/go-gl/gl/v2.1/gl"
	"github.com/go-gl/glfw/v3.3/glfw"
)

func main() {

	var vertices = []float32{
		0.0, 0.0, 0.0,
		0.0, 0.5, 0.0,
		0.5, 0.5, 0.0,
		0.5, 0.0, 0.0,
	}

	err := glfw.Init()
	if err != nil {
		panic(err)
	}
	defer glfw.Terminate()

	window, err := glfw.CreateWindow(640, 480, "第一个窗口", nil, nil)
	if err != nil {
		panic(err)
	}

	window.MakeContextCurrent()

	if err := gl.Init(); err != nil {
		panic(err)
	}

	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.Color3f(1.0, 0.5, 0.2)

	gl.Begin(gl.TRIANGLES)

	gl.Rectd(-0.2, -0.2, 0.0, 0.0)
	gl.Vertex3f(vertices[0], vertices[1], vertices[2])
	gl.Vertex3f(vertices[3], vertices[4], vertices[5])
	gl.Vertex3f(vertices[6], vertices[7], vertices[8])
	fmt.Print(vertices)
	gl.End()

	for !window.ShouldClose() {
		// Do OpenGL stuff.
		window.SwapBuffers()
		glfw.PollEvents()
	}
}
